package jp.dodododo.reloadable.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import jp.dodododo.reloadable.servlet.ServletContextListenerWrapperContainer;
import jp.dodododo.reloadable.servlet.impl.ServletContextListenerWrapperImpl;

public class ServletContextListenerFilter implements Filter {

	private String targetClass;

	public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
		chain.doFilter(req, res);
	}

	public void init(FilterConfig config) throws ServletException {

		targetClass = config.getInitParameter("targetClass");
		ServletContextListenerWrapperContainer.register(new ServletContextListenerWrapperImpl(targetClass));
	}

	public void destroy() {
		targetClass = null;

	}
}
